﻿using CommonLib;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIView_GamePlay : UIViewBase
{
	//1.虚拟摇杆控制

	//2.SkillSlot
	[SerializeField]
	RectTransform SlotLayout;
	//protected List<UIObjectSkill> lstSkillUI;
	protected UIObjectSkill[] arraySkillUI;


	public int SlotCount => arraySkillUI.Length;

	private void Awake()
	{
		//UIObjectSkill[] 
		arraySkillUI = SlotLayout.GetComponentsInChildren<UIObjectSkill>();
		//lstSkillUI = new List<UIObjectSkill>();
		//lstSkillUI.AddRange(arraySkillUI);
	}

	protected override IEnumerator CorOpen()
	{
		ClearSlots();
		return base.CorOpen();
	}

	public void AddSkill()
	{
		var slot = GetAvailableSlot();
		if (null != slot)
			slot.FillSkill();
	}

	public void ClearSlots()
	{
		for (int index = 0; index < arraySkillUI.Length; index++)
		{
			arraySkillUI[index].Clear();
		}
	}

	protected UIObjectSkill GetAvailableSlot()
	{
		for (int index = 0; index < arraySkillUI.Length; index++)
		{
			if (!arraySkillUI[index].IsOccupied)
				return arraySkillUI[index];
		}
		return null;
	}
}
